﻿<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="Cache-Control" content="no-cache"/>
        <title>系统权限管理</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="./css/x-admin.css" media="all">
        <link rel="stylesheet" href="./css/backstage.css" media="all">    
        <script src="./js/jquery.min.js"></script>     
        
        <script>
        	$(function(){
        		randerData();
        	});  
        	//渲染数据
        	function randerData(){
        		$("tbody").empty();
        		
        		$.ajax({
        			url:"../admin/listAdmin",
        			dataType:"json",
        			cache:false,
        			success:function(data){
        				var list=data.obj;
        				var selfId=data.message;  //后台是通过这个message把当前登录用户的id传过来的
        				
        				for(var i=0;i<list.length;i++){
        					var a=list[i];
        					
        					var tr="<tr> <td >"+a.adminName+" </td> <td >"+a.phone+"</td><td> "+a.addTime+" </td> <td>"+a.role+"</td>    "
        					tr+= "<td class='td-manage'>"
        				
        					tr+= "<a title='修改' href='adminedit.html?id="+a.id+"'  class='mlbtn' >修改</a>"        				
        					
        					//用户不能删除自已
        					if(selfId!=a.id){
	        					tr+= "<a title='停用' href='javascript:void(0)'  onclick='delAdmin("+a.id+")'  class='mlbtn' >停用</a>"
        					}
        					tr+= "</td>"
        					tr+= "</tr>"
        					$("#table").append(tr);
        					

                            $("#table tr").attr("bgColor", "white");//为单数行表格设置背景颜色 
                            $("#table tr:even").css("background-color", "#F2F2F2");//为双数行表格设置背颜色素
        				}
        			}
        		});
        	 
        		$(".x-body").height($(document).height());		
        	}
        	

        	 /*删除*/
            function delAdmin(id){
                if(confirm("确定要停用该账号吗")==true){
                	$.ajax({
                		url:"../admin/delAdmin",
                		data:{id:id},
                		async:false,
                		success:function(result){
                          	alert(result.message);
                          	randerData(); 
                		}
                	});
                }
            }
        	 
        </script>
        
    </head>
    <body>
      <div class="wrap">     
        <div class="x-nav">
            <div class="title">
              <a><cite>系统权限管理</cite></a>
              <a href="admin.html" >新增管理员</a>
            </div>
          
        </div>
        <div class="x-body">           
            <table class="layui-table" id="table">
                <thead>
                    <tr>
                        <th> 管理员昵称 </th>
                        <th> 联系方式  </th>
                        <th> 添加日期 </th>
                        <th> 角色 </th>
                        <th> 操作 </th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>      
        </div>
 	  </div>
      
    </body>
</html>